<template>
  <div class="user-info">
    <img
      class="avatar"
      v-if="user.username"
      src="~assets/img/auth/tx.jpg"
      alt=""
    />
    <img class="avatar" v-else src="~assets/img/profile/avatar.svg" alt="" />
    <div class="info">
      <div class="login">
        <span v-if="user.username">{{ user.username }}</span>
        <span v-else @click="handleLogin">登录</span>
        <span class="reg" @click="handleRegister">注册</span>
      </div>
      <div class="phone">
        <img src="~assets/img/profile/phone.svg" alt="" />
        <span>暂无绑定手机号</span>
      </div>
    </div>
    <div class="arrow">
      <img src="~assets/img/common/arrow-left.svg" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  name: "UserInfo",
  data() {
    return {
      user: {},
    };
  },
  methods: {
    // 点击登录
    handleLogin() {
      this.$router.push({
        path: "/auth",
        query: {
          run: "login",
        },
      });
    },
    //点击注册
    handleRegister() {
      this.$router.push({
        path: "/auth",
        query: {
          run: "register",
        },
      });
    },
    //查询store中有没有用户信息
    queryUser() {
      this.user = this.$store.state.user;
    },
  },
  activated() {
    this.queryUser();
  },
};
</script>

<style scoped>
.user-info {
  height: 85px;
  background-color: var(--color-tint);
  padding: 6px 15px;

  display: flex;
  color: #fff;
}

.user-info .avatar {
  width: 70px;
  height: 70px;
}

.info {
  padding-left: 15px;
  flex: 1;
}

.info .login {
  margin-top: 15px;
}

.reg {
  margin-left: 30px;
}

.phone img {
  width: 20px;
  height: 30px;
  vertical-align: middle;
  margin-left: -5px;
}

.phone span {
  font-size: 13px;
}

.arrow {
  width: 20px;
  line-height: 85px;
}

.arrow img {
  width: 20px;
}
</style>